package com.wc._16届国特冲刺营._07数据结构_哈希破题法.最短循环节问题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/28 22:47
 * @description
 * https://www.lanqiao.cn/courses/51805/learning/?id=4072912&compatibility=false
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] ne = new int[N];
    static char[] t;
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        t = (" " + sc.next()).toCharArray();
        int res = 0;
        for (int i = 2, j = 0; i <= n; i++) {
            if (j > 0 && t[i] != t[j + 1]) j = ne[j];
            if (t[i] == t[j + 1]) j++;
            ne[i] = j;
            // 至少有两个的
            if (i >= 2 * j)
                res = Math.max(res, j);
        }

        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

